<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      
      
      <el-form-item label="填报人" prop="fdName">
        <el-input
          v-model="queryParams.fdName"
          placeholder="请输入填报人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="时间" prop="gzsTime">
        <el-date-picker clearable
          v-model="queryParams.gzsTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="时间">
        </el-date-picker>
      </el-form-item>
    
      <el-form-item label="参与领导" prop="gzsParticipate">
        <el-input
          v-model="queryParams.gzsParticipate"
          placeholder="请输入参与领导"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参与辅导员
" prop="gzsFdy">
        <el-input
          v-model="queryParams.gzsFdy"
          placeholder="请输入参与辅导员
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    
      <el-form-item label="活动主题" prop="gzsTheme">
        <el-input
          v-model="queryParams.gzsTheme"
          placeholder="请输入活动主题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teacher:performance:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teacher:performance:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teacher:performance:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teacher:performance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="performanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
     <el-table-column label="填报人" align="center" prop="fdName" />
      <el-table-column label="活动类型" align="center" prop="activeType" />
      <el-table-column label="时间" align="center" prop="gzsTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gzsTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column label="参与领导" align="center" prop="gzsParticipate" />
      <el-table-column label="参与辅导员
" align="center" prop="gzsFdy" />
      <el-table-column label="参与学生" align="center" prop="gzsStu" />
      <el-table-column label="活动主题" align="center" prop="gzsTheme" />
      <el-table-column label="地点" align="center" prop="gzsPlace" />
      <el-table-column label="活动开展介绍" align="center" prop="gzsIntroduce" />
      <el-table-column label="分配比例" align="center" prop="gzsProportion" />
      <el-table-column label="新闻" align="center" prop="gzsNews" />
       <!-- <el-table-column label="图片上传" align="center" prop="gzsPicture" /> -->
       <el-table-column label="照片" align="center" prop="gzsPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.gzsPicture" :width="50" :height="50" />
        </template>
      </el-table-column>
     
     
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teacher:performance:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teacher:performance:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改综合绩效对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

          <el-form-item label="活动类型" prop="activeType" :rules="rules.reason1">
          <el-input v-model="form.activeType" placeholder="请输入活动类型" />
        </el-form-item>


        <el-form-item label="时间" prop="gzsTime" :rules="rules.reason2">
          <el-date-picker clearable
            v-model="form.gzsTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择工作室时间">
          </el-date-picker>
        </el-form-item>
       
        <el-form-item label="参与领导" prop="gzsParticipate" :rules="rules.reason3">
          <el-input v-model="form.gzsParticipate" placeholder="请输入参与领导" />
        </el-form-item>
        <el-form-item label="参与辅导员
" prop="gzsFdy" :rules="rules.reason4">
          <el-input v-model="form.gzsFdy" placeholder="请输入参与辅导员
" />
        </el-form-item>
        <el-form-item label="参与学生" prop="gzsStu" :rules="rules.reason5">
          <el-input v-model="form.gzsStu" placeholder="请输入参与学生" />
        </el-form-item>
        <el-form-item label="活动主题" prop="gzsTheme" :rules="rules.reason6">
          <el-input v-model="form.gzsTheme" placeholder="请输入活动主题" />
        </el-form-item>

         <el-form-item label="地点" prop="gzsPlace" :rules="rules.reason7">
          <el-input v-model="form.gzsPlace" placeholder="请输入工作室地点" />
        </el-form-item>

        <el-form-item label="活动开展介绍" prop="gzsIntroduce" :rules="rules.reason8">
          <el-input v-model="form.gzsIntroduce" placeholder="请输入活动开展介绍" />
        </el-form-item>
        
        
        <el-form-item label="分配比例" prop="gzsProportion" :rules="rules.reason9">
          <el-input v-model="form.gzsProportion" placeholder="请输入分配比例" />
        </el-form-item>
        <el-form-item label="新闻" prop="gzsNews" :rules="rules.reason10">
          <el-input v-model="form.gzsNews" placeholder="请输入新闻" />
        </el-form-item>

        <el-form-item label="照片" prop="gzsPicture" :rules="rules.reason11">
          <image-upload v-model="form.gzsPicture" />
        </el-form-item>
        
      
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPerformance, getPerformance, delPerformance, addPerformance, updatePerformance } from "@/api/teacher/performance";

export default {
  name: "Performance",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 综合绩效表格数据
      performanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fdTime: null,
        creditPass: null,
        yjstatus: null,
        yjidea: null,
        xgstatus: null,
        xgidea: null,
        servingPost: null,
        servingTime: null,
        servingFile: null,
        taskDescribe: null,
        taskTime: null,
        college: null,
        fdName: null,
        activeType: null,
        gzsTime: null,
        gzsPlace: null,
        gzsParticipate: null,
        gzsFdy: null,
        gzsStu: null,
        gzsTheme: null,
        gzsIntroduce: null,
        gzsPicture: null,
        gzsNews: null,
        gzsProportion: null,
        rwType: null,
        rwTime: null,
        rwPlace: null,
        rwParticipate: null,
        rwPeople: null,
        rwTheme: null,
        rwSituation: null,
        rwStu: null,
        rwProportion: null,
        rwFile: null,
        rwNews: null,
        rwPicture: null,
        years: null,
        sucesss: null,
        substatus: null,
        shstatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reason1: [{ required: true, message: "活动类型", trigger: "blur" }],
        reason2: [{ required: true, message: "选择时间", trigger: "blur" }],
        reason3: [{ required: true, message: "参与领导", trigger: "blur" }],
        reason4: [{ required: true, message: "参与辅导员", trigger: "blur" }],
        reason5: [{ required: true, message: "参与学生", trigger: "blur" }],
        reason6: [{ required: true, message: "活动主题", trigger: "blur" }],
        reason7: [{ required: true, message: "地点", trigger: "blur" }],
        reason8: [{ required: true, message: "活动开展介绍", trigger: "blur" }],
        reason9: [{ required: true, message: "分配比例", trigger: "blur" }],  
        reason10: [{ required: true, message: "新闻", trigger: "blur" }],  
        reason11: [{ required: true, message: "图片", trigger: "blur" }],  
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询综合绩效列表 */
    getList() {
      this.loading = true;
      listPerformance(this.queryParams).then(response => {
        this.performanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fdTime: null,
        creditPass: null,
        yjstatus: null,
        yjidea: null,
        xgstatus: null,
        xgidea: null,
        servingPost: null,
        servingTime: null,
        servingFile: null,
        taskDescribe: null,
        taskTime: null,
        college: null,
        fdName: null,
        activeType: null,
        gzsTime: null,
        gzsPlace: null,
        gzsParticipate: null,
        gzsFdy: null,
        gzsStu: null,
        gzsTheme: null,
        gzsIntroduce: null,
        gzsPicture: null,
        gzsNews: null,
        gzsProportion: null,
        rwType: null,
        rwTime: null,
        rwPlace: null,
        rwParticipate: null,
        rwPeople: null,
        rwTheme: null,
        rwSituation: null,
        rwStu: null,
        rwProportion: null,
        rwFile: null,
        rwNews: null,
        rwPicture: null,
        years: null,
        sucesss: null,
        substatus: null,
        shstatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加综合绩效";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPerformance(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改综合绩效";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePerformance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerformance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除综合绩效编号为"' + ids + '"的数据项？').then(function() {
        return delPerformance(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teacher/performance/export', {
        ...this.queryParams
      }, `performance_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
